<?php
namespace app\admin\controller;
use think\Db;
use lib\Curl;
class Aboutus extends Base{
    //广告图
    public function aboutus_banner(){
        if(request()->isGet()){
            $param = input('get.');
            $data=Db::name('aboutus_banner')->where('id',1)->find();
            $this->assign('data',$data);
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['banner']=$param['banner'];
            $res= Db::name('aboutus_banner')->where(array('id'=>1))->update($data);
            if($res){
                return json(['code' => 200,'msg' => '更新成功']);
            }else{
                return json(['code' => 500,'msg' => '失败']);
            }
        }
    }
    public function intro_mission(){
        if(request()->isGet()){
            $param = input('get.');
            $data=Db::name('intro_mission')->where('id',1)->find();
            $this->assign('data',$data);
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['title']=$param['title'];
            $data['subtitle']=$param['subtitle'];
            $data['intro_detail']=$param['intro_detail'];
            $data['culture_title']=$param['culture_title'];
            $data['culture_subtitle']=$param['culture_subtitle'];
            $data['culture_bgimg']=$param['culture_bgimg'];
            $data['our_vision']=$param['our_vision'];
            $data['our_mission']=$param['our_mission'];
            $res= Db::name('intro_mission')->where(array('id'=>1))->update($data);
            if($res){
                return json(['code' => 200,'msg' => '更新成功']);
            }else{
                return json(['code' => 500,'msg' => '失败']);
            }
        }
    }
    public function opinion_value_title(){
        if(request()->isGet()){
            $param = input('get.');
            $data=Db::name('opinion_value_title')->where('id',1)->find();
            $this->assign('data',$data);
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['title']=$param['title'];
            $data['subtitle']=$param['subtitle'];
            $res=Db::name('opinion_value_title')->where(array('id'=>1))->update($data);
            if($res){
                return json(['code' => 200, 'msg' => '成功！']);
            }else{
                return json(['code' => 500, 'msg' => '失败！']);
            }
        }
    }
    public function opinion_value(){
        $list=Db::name('opinion_value')->order('id desc')->paginate(10);
        $counts=Db::name('opinion_value')->count();
        $data=$list->all();
        $this->assign('data',$data);
        $this->assign('list',$list);
        $this->assign('counts',$counts);
        return $this->fetch();
    }
    public function opinion_value_add(){
        if(request()->isGet()){
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['title']=$param['title'];
            $data['description']=$param['description'];
            $data['icon']=$param['icon'];
            $data['sort']=$param['sort'];
            $res= Db::name('opinion_value')->insertGetId($data);
            if($res){
                return json(['code' => 200, 'msg' => '成功！']);
            }else{
                return json(['code' => 500, 'msg' => '失败！']);
            }
        }
    }
    public function opinion_value_edit(){
        if(request()->isGet()){
            $param = input('get.');
            $data=Db::name('opinion_value')->where('id',$param['id'])->find();
            $this->assign('data',$data);
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['title']=$param['title'];
            $data['description']=$param['description'];
            $data['icon']=$param['icon'];
            $data['sort']=$param['sort'];
            $res=Db::name('opinion_value')->where(array('id'=>$param['id']))->update($data);
            if($res){
                return json(['code' => 200, 'msg' => '成功！']);
            }else{
                return json(['code' => 500, 'msg' => '失败！']);
            }
        }
    }
    public function opinion_value_del(){
        $param = input('post.');
        $res= Db::name('opinion_value')->where(array('id'=>$param['id']))->delete();
        return json(['code' => 200,'msg' => '删除成功']);

    }
    public function our_advantages_title(){
        if(request()->isGet()){
            $param = input('get.');
            $data=Db::name('our_advantages_title')->where('id',1)->find();
            $this->assign('data',$data);
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['title']=$param['title'];
            $data['subtitle']=$param['subtitle'];
            $res=Db::name('our_advantages_title')->where(array('id'=>1))->update($data);
            if($res){
                return json(['code' => 200, 'msg' => '成功！']);
            }else{
                return json(['code' => 500, 'msg' => '失败！']);
            }
        }
    }
    public function our_advantages(){
        $list=Db::name('our_advantages')->order('id desc')->paginate(10);
        $counts=Db::name('our_advantages')->count();
        $data=$list->all();
        $this->assign('data',$data);
        $this->assign('list',$list);
        $this->assign('counts',$counts);
        return $this->fetch();
    }
    public function our_advantages_add(){
        if(request()->isGet()){
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['title']=$param['title'];
            $data['description']=$param['description'];
            $data['icon']=$param['icon'];
            $data['sort']=$param['sort'];
            $res= Db::name('our_advantages')->insertGetId($data);
            if($res){
                return json(['code' => 200, 'msg' => '成功！']);
            }else{
                return json(['code' => 500, 'msg' => '失败！']);
            }
        }
    }
    public function our_advantages_edit(){
        if(request()->isGet()){
            $param = input('get.');
            $data=Db::name('our_advantages')->where('id',$param['id'])->find();
            $this->assign('data',$data);
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['title']=$param['title'];
            $data['description']=$param['description'];
            $data['icon']=$param['icon'];
            $data['sort']=$param['sort'];
            $res=Db::name('our_advantages')->where(array('id'=>$param['id']))->update($data);
            if($res){
                return json(['code' => 200, 'msg' => '成功！']);
            }else{
                return json(['code' => 500, 'msg' => '失败！']);
            }
        }
    }
    public function our_advantages_del(){
        $param = input('post.');
        $res= Db::name('our_advantages')->where(array('id'=>$param['id']))->delete();
        return json(['code' => 200,'msg' => '删除成功']);

    }
}